﻿using System;
using System.Drawing;
using System.Web.UI.WebControls;

namespace SBPweb.PhotoGallery.Host
{
    public partial class GalleryViewer : System.Web.UI.UserControl
    {

        #region Private fields

        private Unit pWidth = 320;
        private Unit pHeight = 240;
        private Color pForeground = Color.LightGray;
        private Color pBackground = Color.DarkGray;
        private Color pButtonBackground = Color.Black;
        private Color pButtonForeground = Color.White;
        private Color pButtonBorder = Color.White;
        private Color pButtonPlayForeground = Color.LightGreen;
        private Color pCaptionBackground = Color.Black;
        private Color pCaptionForeground = Color.White;
        private Color pContentBackground = Color.Black;
        private Color pSelectedThumbnailBorder = Color.Yellow;
        private Color pTrackerForeground = Color.Silver;
        private decimal pCaptionOpacity = 0.7M;
        private Font pCaptionFont = new Font(new FontFamily("Verdana"), 11, FontStyle.Regular);
        private Font pTrackerFont = new Font(new FontFamily("Verdana"), 11, FontStyle.Regular);
        private int pBorderRadius = 8;
        private int pPadding = 8;
        private bool pCaptionVisible = true;
        private bool pThumbnailsVisible = true;
        private bool pTrackerVisible = true;
        private bool pAutoPlay = true;
        private ButtonOptions pButtonOption = ButtonOptions.BUTTON_PLAYPAUSE | ButtonOptions.BUTTON_PREVNEXT | ButtonOptions.BUTTON_PREVNEXTPAGE | ButtonOptions.BUTTON_FULLSCREEN | ButtonOptions.BUTTON_SAVE;

        #endregion

        #region Constructor logic

        public GalleryViewer()
        {
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #endregion

        #region Property accessors

        public Slides Slides
        {
            get
            {
                if (Session[ID + "_Slides"] != null)
                {
                    return Session[ID + "_Slides"] as Slides;
                }
                return (Slides)(Session[ID + "_Slides"] = new Slides());
            }
            set
            {
                Session[ID + "_Slides"] = value;
            }
        }

        public Unit Width
        {
            get
            {
                return pWidth;
            }
            set
            {
                pWidth = value;
            }
        }

        public Unit Height
        {
            get
            {
                return pHeight;
            }
            set
            {
                pHeight = value;
            }
        }

        public Color Background
        {
            get
            {
                return pBackground;
            }
            set
            {
                pBackground = value;
            }
        }

        public Color Foreground
        {
            get
            {
                return pForeground;
            }
            set
            {
                pForeground = value;
            }
        }

        public Color ButtonBackground
        {
            get
            {
                return pButtonBackground;
            }
            set
            {
                pButtonBackground = value;
            }
        }

        public Color ButtonForeground
        {
            get
            {
                return pButtonForeground;
            }
            set
            {
                pButtonForeground = value;
            }
        }

        public Color ButtonBorder
        {
            get
            {
                return pButtonBorder;
            }
            set
            {
                pButtonBorder = value;
            }
        }

        public Color ButtonPlayForeground
        {
            get
            {
                return pButtonPlayForeground;
            }
            set
            {
                pButtonPlayForeground = value;
            }
        }

        public Color CaptionBackground
        {
            get
            {
                return pCaptionBackground;
            }
            set
            {
                pCaptionBackground = value;
            }
        }

        public Color CaptionForeground
        {
            get
            {
                return pCaptionForeground;
            }
            set
            {
                pCaptionForeground = value;
            }
        }

        public Color ContentBackground
        {
            get
            {
                return pContentBackground;
            }
            set
            {
                pContentBackground = value;
            }
        }

        public Color SelectedThumbnailBorder
        {
            get
            {
                return pSelectedThumbnailBorder;
            }
            set
            {
                pSelectedThumbnailBorder = value;
            }
        }

        public Color TrackerForeground
        {
            get
            {
                return pTrackerForeground;
            }
            set
            {
                pTrackerForeground = value;
            }
        }

        public decimal CaptionOpacity
        {
            get
            {
                return pCaptionOpacity;
            }
            set
            {
                pCaptionOpacity = value;
            }
        }

        public Font CaptionFont
        {
            get
            {
                return pCaptionFont;
            }
            set
            {
                pCaptionFont = value;
            }
        }

        public Font TrackerFont
        {
            get
            {
                return pTrackerFont;
            }
            set
            {
                pTrackerFont = value;
            }
        }

        public int BorderRadius
        {
            get
            {
                return pBorderRadius;
            }
            set
            {
                pBorderRadius = value;
            }
        }

        public int Padding
        {
            get
            {
                return pPadding;
            }
            set
            {
                pPadding = value;
            }
        }

        public bool CaptionVisible
        {
            get
            {
                return pCaptionVisible;
            }
            set
            {
                pCaptionVisible = value;
            }
        }

        public bool ThumbnailsVisible
        {
            get
            {
                return pThumbnailsVisible;
            }
            set
            {
                pThumbnailsVisible = value;
            }
        }

        public bool TrackerVisible
        {
            get
            {
                return pTrackerVisible;
            }
            set
            {
                pTrackerVisible = value;
            }
        }

        public bool AutoPlay
        {
            get
            {
                return pAutoPlay;
            }
            set
            {
                pAutoPlay = value;
            }
        }

        public ButtonOptions ButtonOption
        {
            get
            {
                return pButtonOption;
            }
            set
            {
                pButtonOption = value;
            }
        }
        
        #endregion

        #region Methods

        public string GetColorName(Color color)
        {
            if (pBackground.IsKnownColor)
            {
                string[] split = color.ToString().Split(new char[] { '[', ']' });

                return split[1];
            }
            return string.Concat("#", (color.ToArgb() & 0x00FFFFFF).ToString("X6"));
        }

        public string GetButtonOptions(ButtonOptions options)
        {
            return options.ToString().Replace(",", " |");
        }

        public string GetBoolean(bool boolean)
        {
            return boolean.ToString().ToLower();
        }

        public string GetFontFamily(Font font)
        {
            return font.FontFamily.Name;
        }

        public string GetFontSize(Font font)
        {
            return font.Size.ToString();
        }

        public string GetFontStyle(Font font)
        {
            switch (font.Style)
            {
                default:
                case FontStyle.Regular:
                    return "Normal";
                case FontStyle.Italic:
                    return "Italic";
            }
        }

        public string GetFontWeight(Font font)
        {
            if (font.Bold)
            {
                return "Bold";
            }
            return "Normal";
        }

        protected override void OnPreRender(EventArgs e)
        {
            litSlides.Text = Slides.ToString();
            base.OnPreRender(e);
        }

        #region Event handlers

        protected void bRefresh_Click(object sender, EventArgs e)
        {
            //Slides = pSlides.Clone(0, ++pI);
        }

        #endregion

        #endregion

        #region Subclasses, enums

        [Flags()]
        public enum ButtonOptions
        {
            BUTTON_PLAYPAUSE = 0,
            BUTTON_PREVNEXT = 1,
            BUTTON_PREVNEXTPAGE = 2,
            BUTTON_FULLSCREEN = 4,
            BUTTON_SAVE = 8
        }

        #endregion

    }
}